package com.capinfo.accounting.web;

import java.lang.reflect.InvocationTargetException;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.capinfo.accumulation.model.accounting.mybist.ZDPZCWPZMB;
import com.capinfo.accumulation.model.accounting.mybist.ZDPZFZZPZMB;
import com.capinfo.accumulation.model.pagemodel.Json;
import com.capinfo.accumulation.parameter.accounting.DataGrid;
import com.capinfo.accumulation.service.accounting.mybits.ZDPZFZZPZMBServiceI;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

/**
 *  @author zxl
 */
@Controller
@RequestMapping("/zDPZFZZPZMBController")
public class ZDPZFZZPZMBController extends BaseController {
	@Autowired
	public ZDPZFZZPZMBServiceI zDPZFZZPZMBService;

	@RequestMapping("/dataGrid.shtml")
	@ResponseBody
	public DataGrid dataGrid(@RequestParam  Map param) {
		return zDPZFZZPZMBService.findbyByGrid(param);
	}
	@RequestMapping("/bj.shtml")
	@ResponseBody
	public Json bj(String jsonString,long id) throws IllegalAccessException, InvocationTargetException
	
	{
			Json j = new Json();

			Gson gson = new Gson();  
			  List<ZDPZFZZPZMB> retList = gson.fromJson(jsonString,  
		                new TypeToken<List<ZDPZFZZPZMB>>() {  
		                }.getType());  
		        for (ZDPZFZZPZMB t : retList) {  
		        	  if(t.getID()!=null){
		            	zDPZFZZPZMBService.updateByPrimaryKeySelective(t);
		        	  }
			        else{
			        	t.setZDPZMBID(id);
			        	zDPZFZZPZMBService.insert(t);
			        }
		        }  
			j.setSuccess(true);
			j.setMsg("保存成功");
			j.setObj("");
		return j;
	}
	@RequestMapping("/add")
	@ResponseBody
	public Json add(ZDPZFZZPZMB t , HttpSession session) {
		Json j = new Json();
		try {
			zDPZFZZPZMBService.insert(t);
			j.setSuccess(true);
			j.setMsg("��ӳɹ���");
			j.setObj(t);
		} catch (Exception e) {
			 e.printStackTrace();
			j.setMsg(e.getMessage());
		}
		return j;
	}

	@RequestMapping("/edit")
	@ResponseBody
	public Json edit(ZDPZFZZPZMB t , HttpSession session) {
		Json j = new Json();
		try {
			zDPZFZZPZMBService.updateByPrimaryKeySelective(t);
			j.setSuccess(true);
			j.setMsg("��ӳɹ���");
			j.setObj(t);
		} catch (Exception e) {
			 e.printStackTrace();
			j.setMsg(e.getMessage());
		}
		return j;
	}

	@RequestMapping("/delete.shtml")
	@ResponseBody
	public Json delete(String id) {
		Json j = new Json();
		try {
			zDPZFZZPZMBService.deleteByPrimaryKey(id);
			j.setSuccess(true);
			j.setMsg("��ӳɹ���");
		} catch (Exception e) {
			 e.printStackTrace();
			j.setMsg(e.getMessage());
		}
		return j;
	}

	@RequestMapping("/selectByid")
	@ResponseBody
	public ZDPZFZZPZMB selectByid(String id) {
		return zDPZFZZPZMBService.selectByPrimaryKey(id);
	}
	
	
	/**
	 * 
	 * @return
	 */
	@RequestMapping("/manager")
	public String manager() {
		return "/zDPZFZZPZMB/zDPZFZZPZMB";
	}
	
	
	/**
	 * 
	 * @return
	 */
	@RequestMapping("/addPage")
	public String addPage(HttpServletRequest request) {
		ZDPZFZZPZMB zDPZFZZPZMB  = new ZDPZFZZPZMB();
		request.setAttribute("zDPZFZZPZMB", zDPZFZZPZMB);
	return "/zDPZFZZPZMB/zDPZFZZPZMBAdd";
	}
	
	/**
	 * 
	 * @return
	 */
	@RequestMapping("/editPage")
	public String editPage(String id ,HttpServletRequest request) {
		ZDPZFZZPZMB zDPZFZZPZMB = this.zDPZFZZPZMBService.selectByPrimaryKey(id);
		request.setAttribute("zDPZFZZPZMB", zDPZFZZPZMB);
		return "/zDPZFZZPZMB/zDPZFZZPZMBEdit";
	}
	
	@RequestMapping("/update.shtml")
	@ResponseBody
	public Json update(String FLXH,String id,String ZDPZMBID) {
		Json j = new Json();
		try {
			zDPZFZZPZMBService.deleteByPrimaryKey1(id,ZDPZMBID);
			zDPZFZZPZMBService.updateByFLXH(FLXH,ZDPZMBID);
			j.setSuccess(true);
			j.setMsg("��ӳɹ���");
		} catch (Exception e) {
			 e.printStackTrace();
			j.setMsg(e.getMessage());
		}
		return j;
		
	}
	
	/**
	 * 
	 * @return
	 */
	@RequestMapping("/viewPage")
	public String viewPage(String id ,HttpServletRequest request) {
		ZDPZFZZPZMB zDPZFZZPZMB = this.zDPZFZZPZMBService.selectByPrimaryKey(id);
		request.setAttribute("zDPZFZZPZMB", zDPZFZZPZMB);
		return "/zDPZFZZPZMB/zDPZFZZPZMBView";
	}
	
}
